home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / quicktime / quicktime for java / zoo tutorial / module10- qtzoo / completed source / progress.java < prev    next >
Encoding:
Java Source  |  2000-06-23  |  4.9 KB  |  152 lines

  1. import java.awt.*;
  2.  
  3. /**
  4.  * The Progress panel that displays progress information and a progress bar
  5.  *
  6.  * @author Levi Brown
  7.  * @author Michael Hopkins
  8.  * @author Apple Computer, Inc.
  9.  * @version 1.0 10/21/1999
  10.  * 
  11.  * Copyright:     © Copyright 1999 Apple Computer, Inc. All rights reserved.
  12.  *    
  13.  * Disclaimer:    IMPORTANT:  This Apple software is supplied to you by Apple Computer, Inc.
  14.  *                ("Apple") in consideration of your agreement to the following terms, and your
  15.  *                use, installation, modification or redistribution of this Apple software
  16.  *                constitutes acceptance of these terms.  If you do not agree with these terms,
  17.  *                please do not use, install, modify or redistribute this Apple software.
  18.  *
  19.  *                In consideration of your agreement to abide by the following terms, and subject
  20.  *                to these terms, Apple grants you a personal, non-exclusive license, under Apple’s
  21.  *                copyrights in this original Apple software (the "Apple Software"), to use,
  22.  *                reproduce, modify and redistribute the Apple Software, with or without
  23.  *                modifications, in source and/or binary forms; provided that if you redistribute
  24.  *                the Apple Software in its entirety and without modifications, you must retain
  25.  *                this notice and the following text and disclaimers in all such redistributions of
  26.  *                the Apple Software.  Neither the name, trademarks, service marks or logos of
  27.  *                Apple Computer, Inc. may be used to endorse or promote products derived from the
  28.  *                Apple Software without specific prior written permission from Apple.  Except as
  29.  *                expressly stated in this notice, no other rights or licenses, express or implied,
  30.  *                are granted by Apple herein, including but not limited to any patent rights that
  31.  *                may be infringed by your derivative works or by other works in which the Apple
  32.  *                Software may be incorporated.
  33.  *
  34.  *                The Apple Software is provided by Apple on an "AS IS" basis.  APPLE MAKES NO
  35.  *                WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
  36.  *                WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  37.  *                PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
  38.  *                COMBINATION WITH YOUR PRODUCTS.
  39.  *
  40.  *                IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
  41.  *                CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  42.  *                GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  43.  *                ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION
  44.  *                OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
  45.  *                (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
  46.  *                ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  47.  * 
  48.  */
  49. public class Progress extends Panel
  50. {
  51.     public Progress(int max)
  52.     {
  53.         this.max = (double)max;
  54.         size = new Dimension(300,81);
  55.         index = 0;
  56.         
  57.         GridBagLayout gridBagLayout;
  58.         gridBagLayout = new GridBagLayout();
  59.         setLayout(gridBagLayout);
  60.         setVisible(false);
  61.         setSize(size);
  62.  
  63.         Dimension sSize = Toolkit.getDefaultToolkit().getScreenSize();
  64.         Dimension dSize = getSize();
  65.         setLocation((sSize.width - dSize.width) >> 1, (int)(0.33333333 * sSize.height));
  66.  
  67.         setBackground(new Color(-1644826));
  68.  
  69.         paramLabel = new java.awt.Label("Gathering the animals...");
  70.         GridBagConstraints gbc;
  71.         gbc = new GridBagConstraints();
  72.         gbc.gridx = 1;
  73.         gbc.gridy = 1;
  74.         gbc.gridwidth = 1;
  75.         gbc.weightx = 0.5;
  76.         gbc.anchor = GridBagConstraints.NORTHWEST;
  77.         gbc.fill = GridBagConstraints.HORIZONTAL;
  78.         gbc.insets = new Insets(10,10,0,10);
  79.         ((GridBagLayout)getLayout()).setConstraints(paramLabel, gbc);
  80.         add(paramLabel);
  81.  
  82.         progressBar1 = new ProgressBar();
  83.         gbc = new GridBagConstraints();
  84.         gbc.gridx = 1;
  85.         gbc.gridy = 2;
  86.         gbc.gridwidth = 1;
  87.         gbc.anchor = GridBagConstraints.CENTER;
  88.         gbc.fill = GridBagConstraints.HORIZONTAL;
  89.         gbc.insets = new Insets(10,10,10,10);
  90.         ((GridBagLayout)getLayout()).setConstraints(progressBar1, gbc);
  91.         add(progressBar1);
  92.     }
  93.     
  94.     public void updateProgress(String text)
  95.     {
  96.         paramLabel.setText(text);
  97.         updateProgress();
  98.     }
  99.     
  100.     public void updateProgress()
  101.     {
  102.         index++;
  103.  
  104.         try
  105.         {
  106.             progressBar1.setPercent(index/max);
  107.         }
  108.         catch (IllegalArgumentException exc) { }
  109.         
  110.         repaint();
  111.     }
  112.     
  113.     public void paint(Graphics g)
  114.     {
  115.         super.paint(g);
  116.         
  117.         Dimension s = getSize();
  118.         int width = s.width - 1;
  119.         int height = s.height - 1;
  120.         
  121.         for (int i = 0; i < 2; ++i)
  122.         {
  123.             width -= i;
  124.             height -= i;
  125.             
  126.             g.setColor(Color.white);
  127.             g.drawLine(i, i, width, i);
  128.             g.drawLine(i, i, i, height);
  129.  
  130.             g.setColor(Color.gray);
  131.             g.drawLine(i, height, width, height);
  132.             g.drawLine(width, i, width, height);
  133.         }
  134.     }
  135.  
  136.     public void update(Graphics g)
  137.     {
  138.         paint(g);
  139.     }
  140.  
  141.     public Dimension getPreferredSize()
  142.     {
  143.         return size;
  144.     }
  145.     
  146.     protected int index;
  147.     protected double max;
  148.     protected Label paramLabel;
  149.     protected Label fileLabel;
  150.     protected ProgressBar progressBar1;
  151.     protected Dimension size;
  152. }